<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消息框</title>
</head>
<body>
<script>
     getName();
     function getName(){
        var userName = prompt('请输入用户名')
            if(userName) {
                alert('你好'+userName);

            }else{
                alert('用户名不能为空');
                 //getName();
            }
              return console.log(userName);

     }
</script>
</body>
</html>